home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEX-UTIL / DVI_DVI1 / dvilj / c / dvifont < prev    next >
Text File  |  1996-02-20  |  29KB  |  840 lines

  1. #include "dvilj.h"
  2.  
  3.  
  4. /*-->GetFontDef*/
  5. /**********************************************************************/
  6. /**************************** GetFontDef  *****************************/
  7. /**********************************************************************/
  8. void
  9. GetFontDef(void)
  10. /***********************************************************************
  11.    Read the font  definitions as they  are in the  postamble of the  DVI
  12.    file.
  13. ***********************************************************************/
  14. {
  15.     unsigned char   byte;
  16.     while (((byte = (unsigned char) NoSignExtend(dvifp, 1)) >= FNT_DEF1) &&
  17.         (byte <= FNT_DEF4)) {
  18.         switch (byte) {
  19.         case FNT_DEF1:
  20.             ReadFontDef ( NoSignExtend(dvifp, 1));
  21.             break;
  22.         case FNT_DEF2:
  23.             ReadFontDef ( NoSignExtend(dvifp, 2));
  24.             break;
  25.         case FNT_DEF3:
  26.             ReadFontDef ( NoSignExtend(dvifp, 3));
  27.             break;
  28.         case FNT_DEF4:
  29.             ReadFontDef ( NoSignExtend(dvifp, 4));
  30.             break;
  31.         default:
  32.             Fatal ("Bad byte value in font defs");
  33.             break;
  34.         }
  35.     }
  36.     if (byte != POST_POST)
  37.         Fatal ("POST_POST missing after fontdefs");
  38. }
  39.  
  40.  
  41. /*-->OpenFontFile*/
  42. /**********************************************************************/
  43. /************************** OpenFontFile  *****************************/
  44. /**********************************************************************/
  45. void
  46. OpenFontFile(void)
  47. /***********************************************************************
  48.     The original version of this dvi driver reopened the font file  each
  49.     time the font changed, resulting in an enormous number of relatively
  50.     expensive file  openings.   This version  keeps  a cache  of  up  to
  51.     MAXOPEN open files,  so that when  a font change  is made, the  file
  52.     pointer, pxlfp, can  usually be  updated from the  cache.  When  the
  53.     file is not found in  the cache, it must  be opened.  In this  case,
  54.     the next empty slot  in the cache  is assigned, or  if the cache  is
  55.     full, the least used font file is closed and its slot reassigned for
  56.     the new file.  Identification\ of the least used file is based on the
  57.     counts of the number  of times each file  has been "opened" by  this
  58.     routine.  On return, the file pointer is always repositioned to  the
  59.     beginning of the file.
  60. ***********************************************************************/
  61.  
  62. #if MAXOPEN > 1
  63.  
  64. {
  65.     int     i, least_used, current;
  66.     struct pixel_list tmp;
  67.     FILEPTR fid;
  68.     struct font_entry *fp;
  69.  
  70. #ifdef DEBUG
  71.     if (Debug)
  72.         fprintf(ERR_STREAM,"open font file %p\n", fontptr->font_file_id);
  73. #endif
  74. /*
  75. fprintf(ERR_STREAM,"? %lx == %lx\n", pfontptr,fontptr);
  76. */
  77.     if ((pfontptr == fontptr) && (pxlfp != NO_FILE))
  78.         return;         /* we need not have been called */
  79.  
  80.        if (fontptr->font_file_id == NO_FILE)
  81.         return;         /* we need not have been called */
  82.  
  83.     tmp = pixel_files[1];
  84.     current = 1;
  85.     while ((current <= nopen) && (tmp.pixel_file_id != fontptr->font_file_id))
  86.     {
  87.         ++current;
  88.         tmp = pixel_files[current];
  89.     }
  90.     /* try to find file in open list */
  91.  
  92.     if (current <= nopen)       /* file already open */ {
  93.         if (pixel_files[current].pixel_file_id != NO_FILE )
  94.         {
  95.             pxlfp = pixel_files[current].pixel_file_id;
  96.             FSEEK(pxlfp, 0l,SEEK_SET);
  97.         }
  98.             /* reposition to start of file */
  99.     } else {
  100.             /* file not in open list          */
  101.         if (nopen < MAXOPEN)    /* just add it to list    */
  102.             current = ++nopen;
  103.         else  {
  104.             /* list full -- find least used file,     */
  105.             /* close it, and reuse slot for new file  */
  106.             least_used = 1;
  107.             for (i = 2; i <= MAXOPEN; ++i)
  108.                 if ((pixel_files[least_used].use_count) > (pixel_files[i].use_count))
  109.                     {least_used = i;}
  110.             if ((fid = pixel_files[least_used].pixel_file_id) != NO_FILE) {
  111.                 /* mark file as being closed in the entry */
  112.                 fp = hfontptr;
  113.                 while ((fp != NULL) && (fp->font_file_id != fid)) {fp = fp->next;}
  114.                 if (fp == NULL)
  115.                    Fatal("Open file %x not found in font entry list.\n", fid);
  116.                 else {
  117.                     fp->font_file_id = FPNULL;
  118.                 }
  119.                 BCLOSE( fid );
  120.             }
  121. #ifdef DEBUG
  122.             if (Debug)
  123.                  fprintf(ERR_STREAM,"\n__reuse slot %d\n", least_used);
  124. #endif
  125.             current = least_used;
  126.         }
  127.         if ((pxlfp = BINOPEN(fontptr->name)) == FPNULL) {
  128.             Warning("PXL-file %s could not be opened", fontptr->name);
  129.             pxlfp = NO_FILE;
  130.         } else {
  131. #ifdef DEBUG
  132.              if (Debug)
  133.            fprintf(ERR_STREAM,"Opening File  <%s> /%p/, Size(font_entry)=%d\n",
  134.                fontptr->name, pxlfp, sizeof(struct font_entry ));
  135. #endif
  136.  
  137.         }
  138.         pixel_files[current].pixel_file_id = pxlfp;
  139.         pixel_files[current].use_count = 0;
  140.     }
  141.     pfontptr = fontptr;         /* make previous = current font */
  142.     fontptr->font_file_id = pxlfp;      /* set file identifier */
  143.     (pixel_files[current].use_count)++;   /* update reference count */
  144. #ifndef USEPXL
  145.     gfin = pxlfp;
  146. #endif
  147. }
  148.  
  149. #else
  150.  
  151. {
  152.   FILEPTR f;
  153.   struct font_entry *fp;
  154.  
  155.     if ((pfontptr == fontptr) && (pxlfp != NO_FILE))
  156.         return;         /* we need not have been called */
  157.  
  158.        if (fontptr->font_file_id == NO_FILE)
  159.         return;         /* we need not have been called */
  160.  
  161.     f = pfontptr->font_file_id;
  162.     if (f != FPNULL)
  163.     {
  164.       if (pxlfp != FPNULL)
  165.       {
  166.         fp = hfontptr;
  167.         while ((fp != NULL) && (fp->font_file_id != f)) {fp = fp->next;}
  168.         if (fp == NULL) {Fatal("Open file %x not found in font entry list.\n",f);}
  169.         else {fp->font_file_id = FPNULL;}
  170.       }
  171.       BCLOSE(f);
  172.     }
  173.     if ((pxlfp = BINOPEN(fontptr->name)) == FPNULL)
  174.     {Warning("PXL-file %s could not be opened", fontptr->name);
  175.      pxlfp = NO_FILE;}
  176.     pfontptr = fontptr;
  177.     fontptr->font_file_id = pxlfp;
  178. }
  179.  
  180. #endif
  181.  
  182.  
  183. /*-->PixRound*/
  184. /**********************************************************************/
  185. /*****************************  PixRound  *****************************/
  186. /**********************************************************************/
  187. long4
  188. PixRound(long4 x, long4 conv)       /* return rounded number of pixels */
  189. /* x in DVI units, conv conversion factor */
  190. {
  191.     return((x + conv) / conv);
  192. }
  193.  
  194.  
  195. #ifdef LJ_RESIDENT_FONTS
  196. /*-->TryResident*/
  197. /**********************************************************************/
  198. /****************************  TryResident  ***************************/
  199. /**********************************************************************/
  200. bool
  201. TryResident(struct font_entry *fontptr)
  202. {
  203.   tfm_info_type tfm_info;
  204.  
  205.   /* To determine if a font is resident, check for a special family
  206.      value (header bytes 12..16 in the TFM file). This seems cleaner,
  207.      and certainly more convenient, than somehow reading an external
  208.      ljfonts.map file in which we'd have to specify information for all
  209.      the resident fonts.  */
  210.   if (tfm_read_info (fontptr->n, &tfm_info)
  211.       && tfm_info.family[0]
  212.       && strcmp (tfm_info.family, "HPAUTOTFM") == 0) {
  213.     unsigned i;
  214.     double factor = fontptr->s / (double) 0x100000;
  215.  
  216.     resident_count++;
  217.     fontptr->resident_p = _TRUE;
  218.     strcpy (fontptr->symbol_set, tfm_info.coding_scheme);
  219.     fontptr->resid = tfm_info.typeface_id;
  220.     fontptr->spacing = tfm_info.spacing;
  221.     fontptr->style = tfm_info.style;
  222.     fontptr->weight = tfm_info.weight;
  223.  
  224.     if (fontptr->spacing == SPACING_FIXED) {
  225.       /* Have to select the point in pitch (characters per inch) instead
  226.          of point size, and thus have to figure out the pitch that
  227.          corresponds to the point size at which the font is used.
  228.  
  229.          To do this, take the width of the interword space, and see how
  230.          many of those characters will fit in the at size. Then convert
  231.          to how many characters will fit in one inch. That's our pitch.
  232.  
  233.          All the builtin LJ4 fonts that are monospaced are Intellifont,
  234.          which have 72.307 points per inch. Not that it really makes any
  235.          difference. We don't worry about this elsewhere, since all
  236.          point sizes are rounded to .25pt anyway, which is more than the
  237.          difference between the various definitions of `point'. */
  238.       double ds_in_points = fontptr->s / 65536.0;
  239.       double w_in_points = tfm_info.interword / (double) 0x100000;
  240.       if (ds_in_points == 0 || w_in_points == 0) {
  241.         /* Avoid division by zero if no interword space. */
  242.         Warning ("%s: Can't determine pitch for this monospaced font.\n",
  243.                  fontptr->n);
  244.         fontptr->pitch = 10; /* Result will look awful, which is good. */
  245.       } else {
  246.         fontptr->pitch = 72.307 / (ds_in_points * w_in_points);
  247.       }
  248.     }
  249.  
  250. #ifdef DEBUG
  251.     if (Debug)
  252.       fprintf(ERR_STREAM, "%6s: typeface=%u\tspacing=%u\tstyle=%u\tweight=%d\n",
  253.               fontptr->n, fontptr->resid, fontptr->spacing,
  254.               fontptr->style, fontptr->weight);
  255. #endif
  256.     for (i = 0; i < NFNTCHARS; i++) {
  257.       struct char_entry *cptr = &(fontptr->ch[i]);
  258.       cptr->tfmw = (long4) (tfm_info.widths[i] * factor);
  259.       cptr->cw = ((fontptr->ch[i].tfmw) / (double) hconv) + .5;
  260.       cptr->width =
  261.     cptr->height =
  262.       cptr->xOffset =
  263.         cptr->yOffset =
  264.           cptr->yyOffset = 0;
  265.     }
  266.     return _TRUE;
  267.   } else {
  268.     fontptr->resident_p = _FALSE;
  269.  
  270.     if (tfm_info.family[0]
  271.     && strcmp (tfm_info.family, "UNSPECIFIED") == 0) {
  272.       Warning("font family for %s is UNSPECIFIED; need to run dvicopy?",
  273.           fontptr->n);
  274.       fontptr->font_file_id = NO_FILE;
  275.       return _TRUE;
  276.     } else {
  277.       return _FALSE;
  278.     }
  279.   }
  280. }
  281. #endif
  282.  
  283.  
  284.  
  285. /*-->ReadFontDef*/
  286. /**********************************************************************/
  287. /****************************  ReadFontDef  ***************************/
  288. /**********************************************************************/
  289. void
  290. ReadFontDef(long4 k)
  291. {
  292.     long4    t;
  293.     unsigned short i;
  294.     struct font_entry *tfontptr; /* temporary font_entry pointer   */
  295.     struct char_entry *tcharptr; /* temporary char_entry pointer  */
  296.     static int      plusid = 0;
  297.     bool font_found = _FALSE;
  298. #ifdef LJ_RESIDENT_FONTS
  299.     bool resident_font_located = _FALSE;
  300. #endif
  301. #ifdef LJ
  302.     int depth, max_depth;
  303. #endif
  304.  
  305. #ifdef DEBUG
  306.     if (Debug)
  307.       fprintf(ERR_STREAM,"Mallocating %d Bytes)...\n", sizeof(struct font_entry ));
  308. #endif
  309.  
  310.     if ((tfontptr = NEW(struct font_entry )) == NULL)
  311.         Fatal("can't malloc space for font_entry");
  312.  
  313.     allocated_storage += sizeof(struct font_entry );
  314.  
  315.     tfontptr->next = hfontptr;
  316.     tfontptr->font_file_id = FPNULL;
  317.     fontptr = hfontptr = tfontptr;
  318.     tfontptr->ncdl = 0;
  319.     tfontptr->k = k;
  320.     tfontptr->c = NoSignExtend(dvifp, 4); /* checksum */
  321.     tfontptr->s = NoSignExtend(dvifp, 4); /* space size */
  322.     tfontptr->d = NoSignExtend(dvifp, 4); /* design size */
  323.     tfontptr->a = (int) NoSignExtend(dvifp, 1); /* length for font name */
  324.     tfontptr->l = (int) NoSignExtend(dvifp, 1); /* device length */
  325.  
  326. #ifdef LJ
  327.     tfontptr->max_width = tfontptr->max_height = tfontptr->max_yoff =
  328.                           max_depth = 0;
  329. #endif
  330.  
  331.     GetBytes(dvifp, tfontptr->n, tfontptr->a + tfontptr->l);
  332.     tfontptr->n[tfontptr->a+tfontptr->l] = '\0';
  333.  
  334.     tfontptr->font_mag = (long4)((
  335.          ActualFactor((long4)(1000.0*tfontptr->s/(double)tfontptr->d+0.5))
  336.          * ActualFactor(mag)
  337. #ifdef USEPXL
  338.          * RESOLUTION * 5.0
  339. #else
  340.          * RESOLUTION
  341. #endif
  342.            ) + 0.5);
  343. /*
  344. printf("[%ld]=%lf * %lf * %lf + 0.5 = %ld\n",
  345.     ((long)(1000.0*tfontptr->s/(double)tfontptr->d+0.5)),
  346.     ActualFactor((long4)(1000.0*tfontptr->s/(double)tfontptr->d+0.5)),
  347.     ActualFactor(mag),
  348.     (double)RESOLUTION * 5,
  349.     (long)tfontptr->font_mag );
  350. */
  351.  
  352. #ifdef LJ_RESIDENT_FONTS
  353.     /* Pass in the name; fills in resident_p and resid (if resident). */
  354.  
  355.     resident_font_located = (bool) TryResident(tfontptr);
  356.  
  357.     if (tfontptr->resident_p)
  358.       return;
  359.  
  360.     if (!(resident_font_located)) {
  361. #endif
  362.  
  363. #ifdef KPATHSEA
  364.     {
  365.       kpse_glyph_file_type font_ret;
  366.       char *name;
  367.       unsigned dpi
  368.         = kpse_magstep_fix ((unsigned) (tfontptr->font_mag / 5.0 + .5),
  369.                             RESOLUTION, NULL);
  370.       tfontptr->font_mag = dpi * 5; /* save correct dpi */
  371.  
  372.       name = kpse_find_pk (tfontptr->n, dpi, &font_ret);
  373.       if (name)
  374.         {
  375.           font_found = _TRUE;
  376.           strcpy (tfontptr->name, name);
  377.           free (name);
  378.  
  379.           if (!STREQ (tfontptr->n, font_ret.name)) {
  380.               fprintf (ERR_STREAM,
  381.                        "dvilj: Font %s not found, using %s at %d instead.\n",
  382.                        tfontptr->n, font_ret.name, font_ret.dpi);
  383.               tfontptr->c = 0; /* no checksum warning */
  384.             }
  385.           else if (!kpse_bitmap_tolerance ((double)font_ret.dpi, (double) dpi))
  386.             fprintf (ERR_STREAM,
  387.                      "dvilj: Font %s at %d not found, using %d instead.\n",
  388.                      tfontptr->name, dpi, font_ret.dpi);
  389.           if (!( (G_noverbatim) || (G_quiet) ) )
  390.             fprintf(ERR_STREAM,"%d: using font <%s>\n", plusid,tfontptr->name);
  391.         }
  392.       else
  393.         {
  394.           tfontptr->font_file_id = NO_FILE;
  395.           fprintf (ERR_STREAM,
  396.             "dvilj: Font %s at %u not found, characters will be left blank.\n",
  397.             tfontptr->n, dpi);
  398.         }
  399.     }
  400. #else /* not KPATHSEA */
  401.       if (!(findfile(PXLpath,
  402.              tfontptr->n,
  403.              tfontptr->font_mag,
  404.              tfontptr->name,
  405.              _FALSE,
  406.              0))) {
  407.     Warning(tfontptr->name); /* contains error messsage */
  408.     tfontptr->font_file_id = NO_FILE;
  409. #ifdef __riscos
  410.         MakeMetafontFile(PXLpath,tfontptr->n,tfontptr->font_mag);
  411. #endif
  412.       }
  413.       else {
  414.     font_found = _TRUE;
  415.     if (!( (G_noverbatim) || (G_quiet) ) )
  416.       fprintf(ERR_STREAM,"%d: using font <%s>\n",
  417.           plusid,tfontptr->name);
  418.       }
  419. #endif /* not KPATHSEA */
  420.  
  421. #ifdef LJ_RESIDENT_FONTS
  422.     }
  423. #endif
  424.  
  425.     tfontptr->plusid = plusid;
  426.     plusid++;
  427.  
  428.     /* sprintf(tfontptr->psname,"%s.%ld.%d",
  429.        tfontptr->n,(long)tfontptr->font_mag,tfontptr->plusid);*/
  430.  
  431. #ifdef LJ
  432.     if (plusid >= HANDLE_MAX_FONTS)
  433.         Fatal("can handle only %d fonts! ask a wizzard...\n",
  434.                HANDLE_MAX_FONTS);
  435. #endif
  436.     if (tfontptr != pfontptr) {
  437.         if (font_found) OpenFontFile();
  438.         else
  439.             pxlfp = NO_FILE;
  440.     }
  441. #ifdef USEPXL
  442.     if ( pxlfp == NO_FILE ) {        /* allow missing pxl files */
  443.         tfontptr->magnification = 0;
  444.         tfontptr->designsize = 0;
  445. #endif
  446.         for (i = FIRSTFNTCHAR; i <= LASTFNTCHAR; i++) {
  447.             tcharptr = &(tfontptr->ch[i]);
  448. #ifdef USEPXL
  449.             tcharptr->width = 0;
  450.             tcharptr->height = 0;
  451.             tcharptr->xOffset = 0;
  452.             tcharptr->yOffset = 0;
  453. #endif
  454.             tcharptr->where.isloaded = _FALSE;
  455.             tcharptr->where.address.fileOffset = NONEXISTANT;
  456.             tcharptr->tfmw = 0;
  457.         }
  458. #ifdef USEPXL
  459.         return;
  460.     }
  461.     t = (long4) NoSignExtend(pxlfp, 1);
  462.     if (t == 0) {
  463.         t = (long4) NoSignExtend(pxlfp, 1);
  464.         t = (long4) NoSignExtend(pxlfp, 2);
  465.         if (t == 1002)
  466.             tfontptr->id = id1002;
  467.         else if (t == 1001)
  468.             tfontptr->id = id1001;
  469.         else
  470.             Fatal("Unknown Version of PXL-format\n");
  471.     } else {
  472.         if (t == PK_PRE)    {
  473.             unsigned char   temp_byte;
  474.             temp_byte = (unsigned char) NoSignExtend(pxlfp, 1);
  475.             if (temp_byte != PK_ID) Fatal(
  476.                "Wrong Version of pk file!  (%d should be 89)\n",
  477.                              (int)temp_byte);
  478.             else
  479.                 tfontptr->id = pk89;
  480.         } else
  481.             Fatal("unknown font format in file <%s> !\n",fontptr->name);
  482.     }
  483.  
  484.     if ((tfontptr->id == id1002) || (tfontptr->id == id1001)) {
  485.         FSEEK(pxlfp, -20l,SEEK_END);
  486.  
  487.         t = NoSignExtend(pxlfp, 4);
  488.         if ((tfontptr->c != 0) && (t != 0) && (tfontptr->c != t))
  489.     Warning("font = \"%s\",\n->tfm checksum = %lX,\n->pxl checksum = %lX",
  490.                           tfontptr->name, tfontptr->c, t);
  491.         tfontptr->magnification = NoSignExtend(pxlfp, 4);
  492.         tfontptr->designsize    = NoSignExtend(pxlfp, 4);
  493.  
  494.         if (tfontptr->id == id1001)
  495.             FSEEK(pxlfp, (long) (NoSignExtend(pxlfp, 4) * 4),SEEK_SET);
  496.         else
  497.             FSEEK(pxlfp, (long) NoSignExtend(pxlfp, 4),SEEK_SET);
  498.  
  499.         for (i = FIRSTFNTCHAR; i <= 127; i++) {   /* only defined for 7bit*/
  500.             tcharptr = &(tfontptr->ch[i]);
  501.             tcharptr->width   = (unsigned short) NoSignExtend(pxlfp, 2);
  502.             tcharptr->height  = (unsigned short) NoSignExtend(pxlfp, 2);
  503.             tcharptr->xOffset = (short) SignExtend(pxlfp, 2);
  504.             tcharptr->yOffset = (short) SignExtend(pxlfp, 2);
  505.             tcharptr->where.isloaded = _FALSE;
  506.             if (tfontptr->id == id1001)
  507.                 tcharptr->where.address.fileOffset = NoSignExtend(pxlfp,4) * 4;
  508.             else
  509.                 tcharptr->where.address.fileOffset = NoSignExtend(pxlfp,4);
  510.             tcharptr->tfmw = (long4)
  511.             (   (double)(NoSignExtend(pxlfp, 4))
  512.               * (double)tfontptr->s / (double) 0x100000 );
  513.             tcharptr->cw = (long4)(((double)tcharptr->tfmw/(double)hconv) + 0.5);
  514.  
  515.             if (tcharptr->width  > CHAR_WIDTH_LARGE  ||
  516.                 tcharptr->height > CHAR_HEIGTH_LARGE )
  517.                 tcharptr->charsize = LARGE_SIZE;
  518.             else
  519.                 tcharptr->charsize = SMALL_SIZE;
  520. #ifdef LJ
  521.             max(tfontptr->max_width,tcharptr->width);
  522.             max(tfontptr->max_height,tcharptr->height);
  523.             if (tcharptr->yOffset > 0  && (int)tfontptr->max_yoff < (int)tcharptr->yOffset)
  524.           tfontptr->max_yoff = tcharptr->yOffset;
  525.             if ((depth = tcharptr->height - tcharptr->yOffset)>max_depth)
  526.                    max_depth = depth;
  527. #endif
  528.  
  529.         }
  530. #ifdef LJ
  531.         tfontptr->max_height = max_depth ? tfontptr->max_yoff+max_depth :
  532.                                            tfontptr->max_yoff+1;
  533. #endif
  534.     } else { /* PK 89 format */
  535.         unsigned char   temp_byte;
  536.         register unsigned char  flag_byte;
  537.         long4    hppp, vppp, pkloc, packet_length;
  538.         int     car, ii;
  539.  
  540.         /* read comment */
  541.         for ( ii = temp_byte = (unsigned char) NoSignExtend(pxlfp, 1);
  542.               ii>0; ii--) {
  543.             flag_byte = (unsigned char) NoSignExtend(pxlfp, 1);
  544. #ifdef DEBUG
  545.             if (Debug) fprintf(ERR_STREAM, "%c", flag_byte ) ;
  546. #endif
  547.         }
  548. #ifdef DEBUG
  549.         if (Debug) fprintf(ERR_STREAM, "\n");
  550. #endif
  551.         pkloc = 3 + (int)temp_byte;
  552.         tfontptr->designsize = NoSignExtend(pxlfp, 4);
  553.  
  554.         t = NoSignExtend(pxlfp, 4);
  555.         if ((tfontptr->c != 0) && (t != 0) && (tfontptr->c != t))
  556.           Warning("font = \"%s\",\n->tfm checksum = %lX,\n->pxl checksum = %lX",
  557.                  tfontptr->name, tfontptr->c, t);
  558.  
  559.         hppp = NoSignExtend(pxlfp, 4);
  560.         vppp = NoSignExtend(pxlfp, 4);
  561.         if (hppp != vppp)
  562.             Warning("aspect ratio is %ld:%ld (should be 1:1)!", (long)hppp,(long)vppp);
  563.         tfontptr->magnification = (long4)(hppp * 72.27 * 5 / 65536l + 0.5);
  564.  
  565.         pkloc += 16;
  566.         flag_byte = skip_specials(&pkloc);
  567.  
  568.         while (flag_byte != PK_POST) {
  569.         if ((flag_byte & 7) == 7) {
  570.         /* fprintf(ERR_STREAM,"\nRead long character preamble\n"); */
  571.  
  572.            packet_length = (unsigned long4)NoSignExtend(pxlfp,4);
  573.            if ((car = (int)NoSignExtend(pxlfp, 4)) > (LASTFNTCHAR))
  574.                 Fatal("Bad character (%d) in PK-File\n",(int)car) ;
  575.  
  576.            tcharptr = &(tfontptr->ch[car]);
  577.            tcharptr->where.address.fileOffset = pkloc;
  578.            /* set pkloc to end_of_packet */
  579.            pkloc += packet_length + 8;
  580.  
  581.            tcharptr->tfmw = (long4) NoSignExtend(pxlfp, 4);
  582.            (void) NoSignExtend(pxlfp, 4); /* horesc not used */
  583.            (void) NoSignExtend(pxlfp, 4); /* not used */
  584.  
  585.            tcharptr ->width   = (unsigned short) NoSignExtend(pxlfp, 4);
  586.            tcharptr ->height  = (unsigned short) NoSignExtend(pxlfp, 4);
  587.            tcharptr ->xOffset = (short) SignExtend(pxlfp, 4);
  588.            tcharptr ->yOffset = (short) SignExtend(pxlfp, 4);
  589.            tcharptr ->where.isloaded = _FALSE;
  590.         } else if (flag_byte & 4) {
  591.             /* fprintf(ERR_STREAM,"Read extended short character preamble\n"); */
  592.  
  593.             packet_length = ((long4) flag_byte & 3) * 65536l +
  594.                 (unsigned short) NoSignExtend(pxlfp, 2);
  595.             if ((car = (int)NoSignExtend(pxlfp, 1)) > (LASTFNTCHAR))
  596.                 Fatal("Bad character (%d) in PK-File\n",(int)car) ;
  597.  
  598.             tcharptr = &(tfontptr->ch[car]);
  599.             tcharptr->where.address.fileOffset = pkloc;
  600.             /* set pkloc to end_of_packet */
  601.             pkloc += packet_length + 3;
  602.  
  603.             tcharptr->tfmw = (long4) NoSignExtend(pxlfp, 3);
  604. /*
  605.             { register unsigned short t;
  606.               t = (unsigned short) NoSignExtend(pxlfp, 1);
  607.               tcharptr->tfmw = t * 65536l +
  608.               (unsigned short) NoSignExtend(pxlfp, 2);
  609.             }
  610. */
  611.             /* horesc not used */
  612.             (void) NoSignExtend(pxlfp, 2) ;
  613.             tcharptr ->width   = (unsigned short) NoSignExtend(pxlfp,2);
  614.             tcharptr ->height  = (unsigned short) NoSignExtend(pxlfp,2);
  615.             tcharptr ->xOffset = (short) SignExtend(pxlfp, 2);
  616.             tcharptr ->yOffset = (short) SignExtend(pxlfp, 2);
  617.             tcharptr ->where.isloaded = _FALSE;
  618.         } else {
  619.             /* fprintf(ERR_STREAM,"<Read short character preamble@>\n"); */
  620.  
  621.             packet_length = ((long4)flag_byte & 3) * 256 +
  622.                 NoSignExtend(pxlfp, 1) ;
  623.             if ((car = (int)NoSignExtend(pxlfp, 1)) > (LASTFNTCHAR))
  624.                 Fatal("Bad character (%d) in PK-File\n",(int)car) ;
  625.  
  626.             tcharptr = &(tfontptr->ch[car]);
  627.             tcharptr->where.address.fileOffset = pkloc;
  628.             /* set pkloc to end_of_packet */
  629.             pkloc += packet_length + 2 ;
  630.  
  631.             tcharptr->tfmw = (long4) NoSignExtend(pxlfp, 3);
  632. /*
  633.             { register unsigned short t;
  634.               t = (unsigned short) NoSignExtend(pxlfp, 1);
  635.               tcharptr->tfmw = t * 65536l +
  636.               (unsigned short) NoSignExtend(pxlfp, 2);
  637.             }
  638. */
  639.             /* horesc not used */
  640.             (void) NoSignExtend(pxlfp, 1) ;
  641.             tcharptr ->width   = (unsigned short) NoSignExtend(pxlfp,1);
  642.             tcharptr ->height  = (unsigned short) NoSignExtend(pxlfp,1);
  643.             tcharptr ->xOffset = (short) SignExtend(pxlfp, 1);
  644.             tcharptr ->yOffset = (short) SignExtend(pxlfp, 1);
  645.             tcharptr ->where.isloaded = _FALSE;
  646.         }
  647.  
  648.         tcharptr->tfmw = (long4)
  649.            ( tcharptr->tfmw * (double)tfontptr->s / (double) 0x100000 );
  650.  
  651.         tcharptr->cw = (long4)(((double)tcharptr->tfmw /
  652.             (double)hconv) + 0.5);
  653.  
  654.         if (tcharptr->width  > CHAR_WIDTH_LARGE  ||
  655.             tcharptr->height > CHAR_HEIGTH_LARGE )
  656.             tcharptr->charsize = LARGE_SIZE;
  657.         else
  658.             tcharptr->charsize = SMALL_SIZE;
  659.  
  660. #ifdef LJ
  661. /*
  662. printf("char=%d: this=%d, max_width=%d, this=%d,max_height=%d, this=%d,max_yoff=%d\n",
  663.        car, tcharptr->width, tfontptr->max_width,
  664.        tcharptr->height,tfontptr->max_height,
  665.        tcharptr->yOffset,tfontptr->max_yoff);
  666. */
  667.         max(tfontptr->max_width, tcharptr->width);
  668.         max(tfontptr->max_height,tcharptr->height);
  669.     if (tcharptr->yOffset > 0  && (int)tfontptr->max_yoff < (int)tcharptr->yOffset)
  670.       tfontptr->max_yoff = tcharptr->yOffset;
  671.  
  672.         if ((depth = tcharptr->height - tcharptr->yOffset) > max_depth)
  673.       max_depth = depth;
  674. #endif
  675. /*
  676. fprintf(ERR_STREAM,"char=%d, yotcharptr=%lx, flag_byte=%d, font=%lx\n",car, tcharptr,flag_byte,tfontptr);
  677. */
  678.         tcharptr->flag_byte = flag_byte;
  679.         FSEEK(pxlfp, (long) pkloc,SEEK_SET);
  680.         flag_byte = skip_specials(&pkloc);
  681.  
  682.         } /* end of while */
  683. #ifdef LJ
  684. tfontptr->max_height = max_depth ? tfontptr->max_yoff+max_depth :
  685.                                    tfontptr->max_yoff+1;
  686. #endif
  687.  
  688. /*
  689. printf("fontid=%d: max_width=%u, max_height=%d, max_yoff=%u\n",
  690.         tfontptr->plusid, tfontptr->max_width,
  691.         tfontptr->max_height, tfontptr->max_yoff);
  692. */
  693.  
  694. #else
  695.     if ( pxlfp == NO_FILE )        /* allow missing pxl files */
  696.     return;
  697.  
  698.     gfin = pxlfp;
  699.     seekpost();
  700.     readpost();
  701.     if ((tfontptr->c != 0) && (checksum != 0) && (tfontptr->c != checksum))
  702.     Warning("font = \"%s\",\n-->font checksum = %d,\n-->dvi checksum = %d",
  703.         tfontptr->name, tfontptr->c, checksum);
  704.  
  705.     for(i=FIRSTFNTCHAR; i<=LASTFNTCHAR; i++) {
  706.     if (char_exists[i]) {
  707.         tcharptr = &(tfontptr->ch[i]);
  708.         tcharptr->tfmw = (long4)(((float)tfm_wd[i]*(float)tfontptr->s) /
  709.            (float)((long4)1l<<20));
  710.         tcharptr->where.address.fileOffset = char_pointer[i];
  711.       }
  712. #ifdef LJ
  713. /*                 GF USER PLEASE CHECK IF THIS CODE WORKS
  714.     tfontptr->max_width = gf_font_max_m;
  715.     tfontptr->max_height = gf_font_max_n;
  716.     tfontptr->max_yoff = gf_font_min_n;
  717. */
  718. #endif
  719. #endif
  720. /*****************************************************************************/
  721. /*if (tcharptr->charsize==LARGE_SIZE)
  722.      fprintf(ERR_STREAM,"%d:\t <%c> w=%d h=%d xO=%d yO=%d tfmw=%ld cw=%ld %d\n",
  723.      i,(char) i,
  724.      tcharptr->width,tcharptr->height,tcharptr->xOffset,tcharptr->yOffset,
  725.      (long)tcharptr->tfmw, (long)tcharptr->cw, (int)(tcharptr->charsize));
  726.  */
  727. /*****************************************************************************/
  728.     }
  729.   }
  730.  
  731.  
  732. /*-->SetFntNum*/
  733. /**********************************************************************/
  734. /****************************  SetFntNum  *****************************/
  735. /**********************************************************************/
  736. void
  737. SetFntNum(long4 k, bool Emitting)
  738. /*  this routine is used to specify the font to be used in printing future
  739.     characters */
  740. {
  741. #ifdef LJ
  742.     static unsigned short plusid = 0;
  743. #endif
  744.     fontptr = hfontptr;
  745.     while ((fontptr != NULL) && (fontptr->k != k))
  746.         fontptr = fontptr->next;
  747.     if (fontptr == NULL)
  748.         Fatal("font %ld undefined", (long)k);
  749.     if (Emitting && fontptr->font_file_id != NO_FILE) {
  750.         if (!fontptr->used_on_this_page
  751. #ifdef LJ_RESIDENT_FONTS
  752.         && !fontptr->resident_p
  753. #endif
  754.         ) {
  755.             fontptr->used_on_this_page = _TRUE;
  756. #ifdef LJ
  757.             if (++fonts_used_on_this_page > MAX_FONTS_PER_PAGE) {
  758.               qfprintf(ERR_STREAM,"this is the %d. font on this page!",
  759.                        fonts_used_on_this_page);
  760.               qfprintf(ERR_STREAM," (max = %d) rastering characters!\n",
  761.                        MAX_FONTS_PER_PAGE);
  762.                rasterfont[fontptr->plusid] = _TRUE;
  763.             }
  764. #endif
  765.         }
  766. #ifdef DEBUG
  767.     if (Debug)
  768.       fprintf(ERR_STREAM, "Switching to font #%ld (%s).\n", k, fontptr->n);
  769. #endif
  770.         /* activate font */
  771. #ifdef IBM3812
  772.         sprintf(PMPformat, "\323%c", (unsigned char)fontptr->plusid);
  773.         PMPout(2, PMPformat);
  774. #endif
  775. #ifdef LJ
  776.         if (!rasterfont[fontptr->plusid]) {
  777. #ifdef LJ_RESIDENT_FONTS
  778.       if (fontptr->resident_p) {
  779. #ifdef DEBUG
  780.             if (Debug)
  781.               fprintf(ERR_STREAM, "Resident font #%d.\n", fontptr->resid);
  782. #endif
  783.         EMIT(EMTO, "\033(%s", fontptr->symbol_set); EMFLUSH;
  784.         EMIT(EMTO, "\033(s%up%.2f%c%us%db%uT",
  785.                 fontptr->spacing,
  786.                 /* height in points, or pitch */
  787.                 fontptr->spacing ? fontptr->s / 65536.0
  788.                                          : fontptr->pitch ,
  789.                         fontptr->spacing ? 'v' : 'h', /* height or pitch? */
  790.                         fontptr->style,       /* upright, italic, ... */
  791.                         fontptr->weight,      /* regular, bold, ... */
  792.                         fontptr->resid); EMFLUSH;
  793.       } else
  794. #endif /* LJ_RESIDENT_FONTS */
  795.           if (fontptr->plusid>0) {EMIT(EMTO, "\033(%dX", fontptr->plusid); EMFLUSH;}
  796.           else                   {EMIT(EMTO, "\033(X"); EMFLUSH;}
  797.         }
  798. /* else fprintf(ERR_STREAM,"I am doing rasterfont for plusid=%d instead\n",
  799.                 fontptr->plusid);
  800. */
  801. #endif
  802.     }
  803. #ifdef LJ    /* reassignment of printer font id  0.48 */
  804.     else if (fontptr->font_file_id != NO_FILE
  805. #ifdef LJ_RESIDENT_FONTS
  806.          && !fontptr->resident_p
  807. #endif
  808.          ) {
  809.       if (fontptr->ncdl == 0) {
  810. #ifdef DEBUG
  811.     if (Debug)
  812.       fprintf(ERR_STREAM, "Changing plusid from %d to %d\n",
  813.           fontptr->plusid, (int)plusid);
  814. #endif
  815.     fontptr -> plusid = plusid;
  816.     plusid ++;
  817.       }
  818.     }
  819. #endif
  820. }
  821.  
  822.  
  823. /*-->SkipFontDef*/
  824. /**********************************************************************/
  825. /****************************  SkipFontDef  ***************************/
  826. /**********************************************************************/
  827. void
  828. SkipFontDef(void)
  829. {
  830.     int     a, l;
  831.     char    n[STRSIZE];
  832.  
  833.     (void) NoSignExtend(dvifp, 4);
  834.     (void) NoSignExtend(dvifp, 4);
  835.     (void) NoSignExtend(dvifp, 4);
  836.     a = (int) NoSignExtend(dvifp, 1);
  837.     l = (int) NoSignExtend(dvifp, 1);
  838.     GetBytes(dvifp, n, a + l);
  839. }
  840.